<?php
class Managecategory_Data_Addedaction {
	
	private $database;
	private $secure;
	
	public function __construct(){
		$this->secure = new Core_Data_Secure();
		$this->database = new Core_Driver_MysqlImproved();
	}
	
	public function addValues(array $postVars){
		$postVars = $this->secure->parseData($postVars);
		
		$name = $postVars['name'];
		$title = $postVars['title'];
		$accessLevel = $postVars['accessLevel'];
		$keywords = $postVars['keywords'];
		$description = $postVars['description'];
		$this->addCategorySettings($name, $accessLevel);
		$this->addCategoryMetaSettings($name, $title, $keywords, $description);
		echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?managecategory">';
	}
	
	private function addCategoryMetaSettings($name, $title, $keywords, $description){
		$this->database->connect();
		$name = $this->database->escape($name);
		$title = $this->database->escape($title);
		$keywords = $this->database->escape($keywords);
		$description = $this->database->escape($description);
		$this->database->prepare(
		"insert into category_meta_values(category_name, category_meta_keywords, category_meta_description, category_meta_title) values('$name', '$keywords', '$description', '$title');"
		);
		$this->database->query();
		$this->database->dataOperations();
	}
	
	private function addCategorySettings($name, $accessLevel){
		$this->database->connect();
		$name = $this->database->escape($name);
		$accessLevel = $this->database->escape($accessLevel);
		$this->database->prepare(
		"insert into category_settings(category_access_level, category_name) values('$accessLevel', '$name');"
		);
		$this->database->query();
		$this->database->dataOperations();
	}
}